package com.iterator.controller.web.statisticalReports;


import com.iterator.service.web.staticalReports.StatService;
import com.iterator.bean.web.lyh.utils.BaseRespVO;
import com.iterator.bean.web.lyh.vo.StatVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/stat")
public class StatController {
    @Autowired
    StatService statService;

    /**
     * SELECT add_time as day,count(*) as users
     * from cskaoyanmall_user
     * group by DATE_FORMAT(add_time, '%Y-%m-%d')
     *
     */
    //用户统计:但是因为数据库的原因,user表缺少add_time,所以显示会有点问题
    @RequestMapping("user")
    @RequiresPermissions("admin:stat:user")
    public BaseRespVO userStat(){
        StatVO statVO = statService.getUserStat();
        return BaseRespVO.ok(statVO);
    }

    /**
     * select sum(actual_price) as amount,count(*) as orders,
     * count(DISTINCT consignee) as customers,add_time as `day`,
     * (sum(actual_price)/count(DISTINCT consignee)) as pcr
     * from cskaoyanmall_order
     * where order_status != 101 and order_status != 102 and order_status != 203
     * group by DATE_FORMAT(add_time, '%Y-%m-%d')
     *
     * 不统计订单状态为101、102、203的订单(退货或者取消的订单)
     */
    //订单统计
    @RequestMapping("order")
    @RequiresPermissions("admin:stat:order")
    public BaseRespVO orderStat(){
        StatVO statVO = statService.getOrderStat();
        return BaseRespVO.ok(statVO);
    }

    /**
     * select sum(price) as amount ,count(DISTINCT order_id) as orders,
     * add_time as `day` , sum(number) as products
     * from cskaoyanmall_order_goods
     * group by DATE_FORMAT(add_time, '%Y-%m-%d')
     *
     * 写的是商品统计,但是实际上是订单的商品统计,这次不排除退货或者取消的订单
     */
    //商品统计:
    @RequestMapping("goods")
    @RequiresPermissions("admin:stat:goods")
    public BaseRespVO goodsStat(){
        StatVO statVO = statService.getGoodsStat();
        return BaseRespVO.ok(statVO);
    }


    /**
     * orderStat的查询思路过程
     *
     * select sum(actual_price) as amount
     * from cskaoyanmall_order
     * where order_status != 101 and order_status != 102 and order_status != 203
     * group by DATE_FORMAT(add_time, '%Y-%m-%d')
     *
     * select count(*) as orders
     * from cskaoyanmall_order
     * group by DATE_FORMAT(add_time, '%Y-%m-%d')
     *
     * select count(DISTINCT consignee) as customers
     * from cskaoyanmall_order
     * group by DATE_FORMAT(add_time, '%Y-%m-%d')
     *
     * select add_time as `day`
     * from cskaoyanmall_order
     * group by DATE_FORMAT(add_time, '%Y-%m-%d')
     *
     * select (sum(actual_price)/count(DISTINCT consignee)) as pcr
     * from cskaoyanmall_order
     * group by DATE_FORMAT(add_time, '%Y-%m-%d')
     *
     *
     *
     * select sum(actual_price) as amount,count(*) as orders,count(DISTINCT consignee) as customers,add_time as `day`,(sum(actual_price)/count(DISTINCT consignee)) as pcr
     * from cskaoyanmall_order
     * where order_status != 101 and order_status != 102 and order_status != 203
     * group by DATE_FORMAT(add_time, '%Y-%m-%d')
     */
}
